# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: fossdd <fossdd@pwned.life>
pkgname=aws-crt-cpp
pkgver=0.29.0
pkgrel=0
pkgdesc="C++ wrapper around the aws-c-* libraries. Provides Cross-Platform Transport Protocols and SSL/TLS implementations for C++"
url="https://github.com/awslabs/aws-crt-cpp"
# s390x: aws-c-common
arch="all !s390x"
license="Apache-2.0"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	aws-c-auth-dev
	aws-c-cal-dev
	aws-c-common-dev
	aws-c-compression-dev
	aws-c-event-stream-dev
	aws-c-http-dev
	aws-c-io-dev
	aws-c-mqtt-dev
	aws-c-s3-dev
	aws-c-sdkutils-dev
	aws-checksums-dev
	s2n-tls-dev
	"
makedepends="
	$depends_dev
	cmake
	samurai
	"
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/awslabs/aws-crt-cpp/archive/refs/tags/v$pkgver.tar.gz"
options="net"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja\
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=/usr/lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DBUILD_DEPS=False \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)" \
		$crossopts
	cmake --build build
}

check() {
	ctest --test-dir build --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	# just test binaries
	# shellcheck disable=2115
	rm -rf "$pkgdir"/usr/bin/
}

dev() {
	default_dev
	amove usr/lib/aws-crt-cpp
}

sha512sums="
09443cedf37a340a0557992c5ab33855113fe24e618eeb2309f6e29fa1e961a52544afda8fdea6bf83d68e8eb5a771af2ad4e010c0ffe9d38793044ca66f7650  aws-crt-cpp-0.29.0.tar.gz
"
